package main

import (
	"time"
	_ "user-center/controller"

	"log"

	"github.com/androidsr/sc-go/proxy"
	"github.com/androidsr/sc-go/sbuilder"
	"github.com/androidsr/sc-go/sgin"
	"github.com/androidsr/sc-go/sgorm"
	"github.com/androidsr/sc-go/sno"
	"github.com/androidsr/sc-go/syaml"
)

func main() {
	log.SetFlags(log.Llongfile | log.LstdFlags)
	config, err := syaml.LoadFile[syaml.ScRoot]("user-center.yaml")
	if err != nil {
		panic(err)
	}
	sgorm.DB = sgorm.New(config.Sc.Gorm)
	sno.New(*config.Sc.Snowflake)
	router := sgin.New(config.Sc.Gin)
	router.Cors()
	router.WebToken(config.Sc.Jwt)

	addFill(router)
	go func() {
		router.RunServer()
	}()
	proxy.New(config.Sc.Proxy)
}

func addFill(router *sgin.SGin) {
	sbuilder.AddInsertFill("id", func() any {
		return sno.GetString()
	})
	sbuilder.AddInsertFill("create_time", func() any {
		return time.Now()
	})
	sbuilder.AddUpdateFill("update_time", func() any {
		return time.Now()
	})
}
